package com.ithehema;

import java.util.Scanner;
public class StringDemo02 {
    public static void main(String[] args) {
        //1.定义二个变量记录正确的用户名和密码
        String rightUsername = "zhangsan";
        String rightPassword = "123456";
        Scanner sc = new Scanner(System.in);
        int count=3;
        for (int i = 0; i < 3; i++) {
            //2.键盘录入用户名和密码
            System.out.println("请输入用户名");
            String username = sc.next();
            System.out.println("请输入密码");
            String password = sc.next();
            //3.比较
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                System.out.println("登录成功");
                break;
            }
            else {
                count--;
               if(count==0){
                   //最后一次机会也输入错误，此时要提升账号被锁定
                   System.out.println("账户"+username+"被锁定，请联系我");
               }
               else {

                   System.out.println("登录失败，重新登录,您还剩下"+count+"次机会");
               }

            }
        }

    }
}
